#include<string>
#include<iostream>
#define USUAL_DELETE
#include"Singleton.h"

Singleton * Singleton::self = 0;

int Singleton::counter = 0;

std::string Singleton::toString() const {
        std::string str(str_);
	return str;
}

Singleton::~Singleton() {
    delete[] self->str_;
    self->str_ = 0;
    self->size_ = 0;
}

void Singleton::deleteObj() {
    --Singleton::counter;
    if(Singleton::counter == 0) {
        if(Singleton::self) {
            delete Singleton::self;
            Singleton::self = 0;
        }
    }
}

Singleton::Singleton(std::string const & str) : str_(new char[str.size() + 1]), size_(str.size()) {
    for(size_t i = 0; i < size_; ++i) {
        str_[i] = str[i];
    }
    str_[size_++] = '\0';
}

Singleton::Singleton(Singleton const & copy) { }

void Singleton::swap(Singleton & right) {
	std::swap(this->str_, right.str_);
}
